﻿<!DOCTYPE html>
<html>
	<head>
		<title>V10授权登录</title>
		<meta name="format-detection" content="telephone=no,email=no" />
		<meta name="viewport" content="width=device-width, user-scalable=no">
		<script type="text/javascript" src="src/assets/js/jquery.min.js"></script>
		<script type="text/javascript" src="src/assets/js/layer/layer.js"></script>
		<script type="text/javascript" src="src/openapiConfig.js"></script>
	</head>
	<body onload="authLogin()">
	</body>
	<script>
		//授权登录
		var openApiUrl = openApiObj.apiUrl;
		var ajaxUrl = openApiUrl + "/member/getPartnerByToken.do";
		function authLogin(){
			var token = getQueryString("token");
			$.ajax({
				url: ajaxUrl,
			    type: "post",
			    dataType:'json', 
			    data:{
			    	"token":token
			    },
			    success:function(data){
			    	if(data.result == "1"){
			    		var partnerInfo = data.resData;
			    		var userId = partnerInfo.id;
						var userName = partnerInfo.accountName;
						window.localStorage.setItem("userId", userId);
			    		window.localStorage.setItem("userName", userName);
				        window.localStorage.setItem("isLogin", true);
						//跳转渠道王页面进行登录操作
						window.location.href = "index.html";
			    	}else{
			   			layer.msg("授权登录失败,即将跳回登录页面!", {
							time: 3000
						}, function(){
							window.localStorage.setItem("isLogin", "");
							window.location.href = "index.html";
						});   
			    	}
		    	}
			});
		}
		//获取当前页面url入参
		function getQueryString(name){
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
			var r = window.location.search.substr(1).match(reg); 
			if (r != null) {
				return decodeURI(r[2]);
			}
			return "";
		}
	</script>
</html>
